define(function(require, exports, module)
{
    var $ = require("$");
    require("bootstrap_commonrequire");
    require("moment");
    require("bootstrap-daterangepicker");
    
    require("bootstrap");

    require("bootstrap.css");
    require("bootstrap-responsive.css");
    require("theme-colors.css");
    
    require("daterangepicker.css");
    
    /*监听窗口大小变化，增强jquery的resize方法，可以激情dom元素*/
    require('js/core/jquery/src/jquery_resize');
    
    /*添加ztree引用*/
    require("zTreeStyle.css");
	  require("ztreeCore");
	  require("ztreeExcheck");
    
    require('select2.css');
    require('select2');
    var store = require('store');
    var bootbox = require('bootbox');
    
    exports.init = function(param)
    {
        
        $(document).ready(function()
        {
    		
    		//获取查询条件
    		function getCondition() {
    			
    			var sessionid = $('#sessionid').text();
    			
    			var queryStr = "";
    			
    			if(sessionid != '' && sessionid != null) {
            queryStr =  sessionid ;
          }
    			
    			return queryStr;
    		}
    			
    		//加载表单模板和数据
    		var Table = require("table");
            new Table(
            {
                attrs :
                {
                    id : "datatableid",
                    isHovered : false,
                    isStriped : true,
                    isBordered : false
                },
                renderTo : param.divWrapperId
               
            });
            
            var dtUtil = require('datatableutil');
            
            var datatable = $('#datatableid').dataTable({
                   "sDom" : "<'hidden'<'span6'l><'hidden'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
                   "bJQueryUI" : false,
                   "oLanguage" :
                   {
                       "sUrl" : "/business/js/common/table/src/lang/dataTable.cn.txt"
                   },
                   "sPaginationType" : "bootstrap", // 分页自带两种样式，full_numbers和two_button(默认)
                   'bPaginate' : true, // 是否分页
                   "bProcessing" : true, // 当datatable获取数据时候是否显示正在处理提示信息。
                   "bServerSide" : true, // 指定服务器端分页
                   "bDeferRender" : true,
                   "bFilter" : true,
                   "bSort" : true,
                   "bInfo" : true,
                   "sAjaxSource" : "/data/queryPhoneBillBySessionId.do", // 数据源
                   "iDisplayLength" : DATATABLES_CONFIG.iDisplayLength.DEFAULT,  // 默认分页的每页记录数
                   "fnServerData" : function(sSource, aoData, fnCallback, oSettings)
                   {
                	   
                       var queryparam = dtUtil.convert_aoData(aoData);
                       
                       //拼接where查询条件
                       var cond = getCondition();
                       if(cond != '' && cond != null) {
                       	queryparam.q += cond;
                       }
                        
                       // 添加自己的额外参数
                       oSettings.jqXHR = $.ajax(
                       {
                           "dataType" : 'json',
                           "contentType" : "application/json;charset=UTF-8",
                           "type" : "GET",
                           "url" : sSource,
                           "data" : queryparam, // 将请求数据转换为后台要求的JSON格式
                           "success" : function(json)
                           {
                               dtUtil.successCallback(json, aoData, fnCallback);
                           }
                       });
                       
                   },
                   "aoColumns" : [
                     
                                  {
                                    "sTitle" : "被叫号码",
                                    "bSortable" : false,
                                    "mData" : "callee"
                                },
                                {
                                    "sTitle" : "通话开始时间",
                                    "bSortable" : false,
                                    "mData" : "beginTime",
                                    "mRender" : function(data, type, full)
                                    {
                                    
                                      var retData = data.substr(0,4)+"-"+data.substr(4,2)+"-"
                                                        +data.substr(6,2)+" "+data.substr(8,2)+":"
                                                        +data.substr(10,2)+":"+data.substr(12,2);
                                      
                                      return retData;
                                      
                                      
                                    }
                                },
                                {
                                    "sTitle" : "通话结束时间",
                                    "bSortable" : false,
                                    "mData" : "endTime",
                                    "mRender" : function(data, type, full)
                                    {
                                    
                                      var retData = data.substr(0,4)+"-"+data.substr(4,2)+"-"
                                                        +data.substr(6,2)+" "+data.substr(8,2)+":"
                                                        +data.substr(10,2)+":"+data.substr(12,2);
                                      
                                      return retData;
                                      
                                      
                                    }
                                      
                                },
                                {
                                    "sTitle" : "通话时长(分钟)",
                                    "bSortable" : false,
                                    "mData" : "time",
                                    "mRender" : function(data, type, full)
                                    {
                                      return data%60==0?(data/60):Math.ceil(data/60);
                                    }
                                }
                                
                                ],
               	"fnDrawCallback": function( oSettings ) {
                   	// 表格绘制完成后，去除width属性，使表格可缩放
                   	$('#'+oSettings.sTableId).css("width", "");
                   }
                   
             });
        
        });
        
    };
    
});

